/**
 * Author: Andrew Shore
 * Date Last Modified: April 14, 2009
 * CSCE 146: Homework 07, ProcessRecord.java
 * 
 * Description:
 * Basic data payload for the priority queue. Has three class variables: pid is
 * the unique process id, priority is used to sort the process record in the queue,
 * and processQ determines the records place in the MultiList(can be between 1 and 8). 
 */
import java.util.Scanner;


public class ProcessRecord implements IProcessRecord{
	
	private int pid;
	private int priority;
	private int processQ;
	
	/**
	 * Default Constructor
	 */
	public ProcessRecord(){
		pid = 0;
		priority = 0;
		processQ = 0;
	}
	
	/**
	 * Accessors
	 */
	public int getPid() {
		return pid;
	}
	public int getPriority() {
		return priority;
	}
	public int getProcessQ() {
		return processQ;
	}

	/**
	 * Mutators
	 */
	public void setPid(int what) {
		pid = what;
	}
	public void setPriority(int what) {
		priority = what;	
	}
	public void setProcessQ(int what) {
		processQ = what;
	}
	
	/**
	 * Method to read a single Record and initialize the instance variables.
	 * 
	 * Parameters: inFile - file containing the information for the process records
	 * 
	 * File is assumed to be in the correct format.
	 */
	public ProcessRecord readProcessRecord(Scanner inFile) {
		int n;
		
		if(inFile.hasNext()){
			n = inFile.nextInt();
			this.setPid(n);
			
			n = inFile.nextInt();
			this.setPriority(n);
			
			n = inFile.nextInt();
			this.setProcessQ(n);
			
		}
		
		return this;
	}

	/**
	 * Method to compare the priorities of two records, 
	 * if the calling class's priority is greater 	return 1,
	 * if the parameter's priority is greater 		return -1,
	 * and if they are equal 						return 0
	 * 
	 * Parameters: that - process record being compared
	 */
	public int compareTo(ProcessRecord that) {
		
		if(this.getPriority() > that.getPriority()){
			return 1;
		}
		else if(this.getPriority() < that.getPriority()){
			return -1;
		}
		else {
			return 0;	
		}
	}
	
	/**
	 * Method to assign the variables of a ProcessRecord to a String value
	 */
	public String toString(){
		String a = "";
		a += "	" + pid + "	" + priority + "	" + processQ;
		return a;
	}



}
